//
//  renyaun.m
//  PASystem
//
//  Created by michael on 16/9/19.
//  Copyright © 2016年 czd. All rights reserved.
//

#import "renyaun.h"
#import "renyuanTableViewCell.h"

@implementation renyaun

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
    UIColor *myColor = [UIColor colorWithWhite:0.8 alpha:0.3];
self.backgroundColor = myColor;

          }
    return self;
}
- (void)setId:(NSString *)id{


//NSLog(@"11%@",id);
_id = id;
 [self initview];
[self request];
 
}
- (void)initview{
        self.ViewController.automaticallyAdjustsScrollViewInsets = YES;
_tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
 
_tableView.frame = CGRectMake(10,10, KScreenWidth-20, KScreenHeight-64-46-40-20);
_tableView.backgroundColor = [UIColor whiteColor];
_tableView.dataSource = self;
_tableView.delegate = self;
self.tableView.bounces = NO;
[self addSubview:_tableView];
}
- (void)request{
NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];
    NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];
    
 NSString *json =[NSString stringWithFormat: @"{'action':qyzryList,'service':ZCQService, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,code:%@,chapter:%@}'}",userId,pwdId,userHumber,_id,_pid];
     NSArray * array = @[@{@"arg0":json}];
    [HttpTools requestWithURL:BaseURL arrays:array method:Basemethod success:^(id JSON) {
 _dataArray = [NSMutableArray array];
     NSArray *array = JSON[@"reason"];
        for (NSDictionary *dic in array) {
    NSDictionary *dict = dic[@"attrs"];
    [_dataArray addObject:dict];
    
} [self.tableView reloadData];
       


    }
     failure:^(NSError *error) {
        

    }];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  _dataArray.count;
}
#pragma mark UITableView dataScource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
 static NSString *CellIdentifier = @"Cell";  

    renyuanTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  if (cell==nil) {  
        cell=[[renyuanTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        
    }
    NSDictionary *dic = _dataArray [indexPath.row];
    cell.dict = dic;

    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 120;
}

@end
